import fpGrowth
rootNode = fpGrowth.treeNode('pyramid',9,None)
#为树中的单个节点增加一个子节点
rootNode.children['eye'] = fpGrowth.treeNode('eye',13,None)
rootNode.children['phoenix'] = fpGrowth.treeNode('phoenix',3,None)
rootNode.disp()

#12-3根据数据集来生成FP树
simpDat = fpGrowth.loadSimpDat()
print('simpDat\n',simpDat)
#对数据进行格式化处理
initSet = fpGrowth.createInitSet(simpDat)
print('initSet\n',initSet)
#创建FP树
myFPtree , myHeaderTab = fpGrowth.createTree(initSet,3)
myFPtree.disp()
print("myHeaderTab\n",myHeaderTab)
#############生成了FP树后的操作########
pathx = fpGrowth.findPrefixPath('x',myHeaderTab['x'][1])
print("pathx\n",pathx)
pathz = fpGrowth.findPrefixPath('z',myHeaderTab['z'][1])
print("pathz\n",pathz)
pathr = fpGrowth.findPrefixPath('r',myHeaderTab['r'][1])
print("pathr\n",pathr)

#############构建条件树#############3
freqItems = []#储存所有的频繁项集
fpGrowth.mineTree(myFPtree , myHeaderTab ,3, set([]),freqItems)
print("freqItems\n",freqItems)

#######从新闻网站点击流中挖掘##################
#每一行标记的是该用户看了哪几个报道
parsedDat = [line.split() for line in open('kosarak.dat').readlines()]
lineSet = fpGrowth.createInitSet(parsedDat)
#寻找至少被10万人浏览过的新闻报道
myFPtree , myHeaderTab = fpGrowth.createTree(lineSet,100000)
myFreqList = []
fpGrowth.mineTree(myFPtree,myHeaderTab,100000,set([]),myFreqList)
print("len(myFreqList)\n",len(myFreqList))
print("myFreqList",myFreqList)
